/*
 * Copyright (c) 2006-2025, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2025-10-14     RT-Thread    led blink thread
 */

#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>

#define LED1_PIN    GET_PIN(G, 14)
#define LED2_PIN    GET_PIN(I, 0)
#define LED3_PIN    GET_PIN(I, 1)

#define LED_THREAD_PRIORITY     20
#define LED_THREAD_STACK_SIZE   512
#define LED_THREAD_TIMESLICE    5


static void led_thread_entry(void *parameter)
{
    rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(LED2_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(LED3_PIN, PIN_MODE_OUTPUT);

    while (1)
    {
        rt_pin_write(LED1_PIN, PIN_LOW);
        rt_pin_write(LED2_PIN, PIN_HIGH);
        rt_pin_write(LED3_PIN, PIN_HIGH);
        rt_thread_mdelay(300);

        rt_pin_write(LED1_PIN, PIN_HIGH);
        rt_pin_write(LED2_PIN, PIN_LOW);
        rt_pin_write(LED3_PIN, PIN_HIGH);
        rt_thread_mdelay(300);

        rt_pin_write(LED1_PIN, PIN_HIGH);
        rt_pin_write(LED2_PIN, PIN_HIGH);
        rt_pin_write(LED3_PIN, PIN_LOW);
        rt_thread_mdelay(300);
    }
}


int led_blink_init(void)
{
    rt_thread_t led_thread = RT_NULL;

    led_thread = rt_thread_create("led_blink",
                                   led_thread_entry,
                                   RT_NULL,
                                   LED_THREAD_STACK_SIZE,
                                   LED_THREAD_PRIORITY,
                                   LED_THREAD_TIMESLICE);

    if (led_thread != RT_NULL)
    {
        rt_thread_startup(led_thread);
    }

    return RT_EOK;
}


